package com.huanuo.internetofthings.service.enterpriseCustom;

import com.huanuo.internetofthings.bo.enterpriseCustom.EnterpriseCustom;
import com.huanuo.internetofthings.dao.enterpriseCustom.EnterpriseCustomMapper;
import com.huanuo.internetofthings.dto.enterpriseCustom.EnterpriseCustomPageRequestDto;
import org.springframework.stereotype.Service;
import org.unicorn.framework.base.base.AbstractService;
import org.unicorn.framework.core.exception.PendingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.unicorn.framework.core.SysCode;
import java.util.List;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
/**
 * <p>
 * 设备客户表 服务实现类
 * </p>
 *
 * @author xiebin
 * @since 2018-07-25
 */
@Service
public class EnterpriseCustomService extends AbstractService {
  @Autowired
  private EnterpriseCustomMapper enterpriseCustomMapper;
  /**
     * 根据主键删除记录
     * @param id
     * @return
     * @throws PendingException
     */
  public void deleteByPrimaryKey(Long id) throws PendingException{
    try {
			 enterpriseCustomMapper.deleteByPrimaryKey(id);
		} catch (Exception e) {
			error("删除记录失败", e);
			throw new PendingException(SysCode.DB_ERROR, "删除记录失败");
	}
    
  }


   /**
     * 保存记录
     * @param record
     * @return
     * @throws PendingException
     */
   public  EnterpriseCustom save(EnterpriseCustom record) throws PendingException{
       try {
			 enterpriseCustomMapper.insertSelective(record);
			 return record;
		} catch (Exception e) {
			error("新增记录失败", e);
			throw new PendingException(SysCode.DB_ERROR, "新增记录失败");
	}
   }
      /**
     * 根据主键查询记录
     * @param record
     * @return
     * @throws PendingException
     */
    public EnterpriseCustom selectByPrimaryKey(Long id) throws PendingException{
    try {
			return enterpriseCustomMapper.selectByPrimaryKey(id);
		} catch (Exception e) {
			error("查询记录失败", e);
			throw new PendingException(SysCode.DB_ERROR, "查询记录失败");
	}
    }
    
     /**
     * 根据条件查询记录列表
     * @param record
     * @return
     * @throws PendingException
     */
    public  List<EnterpriseCustom> selectList(EnterpriseCustom record) throws PendingException{
       try {
			return enterpriseCustomMapper.selectList(record);
		} catch (Exception e) {
			error("查询列表失败", e);
			throw new PendingException(SysCode.DB_ERROR, "查询列表失败");
	}
    }
    
    /** 
	 * 分页查询设备客户表信息
	 * 
	 * @param enterpriseCustomPageRequestDto
	 * @return
	 * @throws PendingException
	 */
	public PageInfo<EnterpriseCustom> getEnterpriseCustomByPage(EnterpriseCustomPageRequestDto enterpriseCustomPageRequestDto)
			throws PendingException {
		try {
			PageHelper.startPage(enterpriseCustomPageRequestDto.getPageNo(),enterpriseCustomPageRequestDto.getPageSize());
			List<EnterpriseCustom> list=enterpriseCustomMapper.selectList(enterpriseCustomPageRequestDto.getEnterpriseCustom());
			PageInfo<EnterpriseCustom> pageInfo = new PageInfo<>(list);
			return pageInfo;
		}catch (Exception e) {
			error("分页查询设备客户表失败", e);
			throw new PendingException(SysCode.DB_ERROR, "分页查询设备客户表失败");
		}
	}
    
    /**
     * 根据主键列表查询记录
     * @param record
     * @return
     * @throws PendingException
     */
    public  List<EnterpriseCustom> selectListByIds(List<Long> ids) throws PendingException{
     try {
			return enterpriseCustomMapper.selectListByIds(ids);
		} catch (Exception e) {
			error("根据ID列表批量查询记录失败", e);
			throw new PendingException(SysCode.DB_ERROR, "根据ID列表批量查询记录失败");
	}
    }
   /**
     * 根据条件查询一条记录
     * @param record
     * @return
     * @throws PendingException
     */
    public  EnterpriseCustom selectOne(EnterpriseCustom record) throws PendingException{
      try {
			return enterpriseCustomMapper.selectOne(record);
		} catch (Exception e) {
			error("查询单条记录失败", e);
			throw new PendingException(SysCode.DB_ERROR, "查询单条记录失败");
	}
    }

    /**
     * 根据主键修改记录
     * @param record
     * @return
     * @throws PendingException
     */
    public EnterpriseCustom updateByPrimaryKey(EnterpriseCustom record) throws PendingException{
       try {
			 enterpriseCustomMapper.updateByPrimaryKey(record);
			return record;
		} catch (Exception e) {
			error("根据主键更新单条记录失败", e);
			throw new PendingException(SysCode.DB_ERROR, "根据主键更新单条记录失败");
	}
    }
}
